/**
 *
 */
package model;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import util.ApplicationProperties;

/**
 * Represents a series season.
 * 
 * @author Marco
 */
public class Season implements IFile {
    public static String  SEASON_LABEL;
    private File          seasonFolder;
    private int           seasonNumber;
    private List<Episode> episodeList;

    static {
        SEASON_LABEL = ApplicationProperties.getSeasonLabel();
    }

    public Season(File aLanguage, int aSeasonNumber) {
        seasonFolder = new File(aLanguage, SEASON_LABEL + aSeasonNumber);
        seasonNumber = aSeasonNumber;
    }

    /**
     * @return the seasonNumber
     */
    public int getSeasonNumber() {
        return seasonNumber;
    }

    /**
     * @return the episodeList
     */
    public List<Episode> getEpisodeList() {
        return episodeList;
    }

    /*
     * (non-Javadoc)
     * 
     * @see IFile#getFile()
     */
    @Override
    public File getFile() {
        return seasonFolder;
    }

    public static List<Season> createSeasonListFromLanguageFolder(
            Language aLanguage) {
        List<Season> tempSeasonList = new ArrayList<Season>(24);
        for (File tempSeasonFolder : aLanguage.getFile().listFiles()) {
            if (tempSeasonFolder.isDirectory()
                    && tempSeasonFolder.getName().startsWith(SEASON_LABEL)) {
                String[] tempSeasonNameParts = tempSeasonFolder.getName()
                        .split(" ");
                int tempSeasonNumber = Integer
                        .parseInt(tempSeasonNameParts[tempSeasonNameParts.length - 1]);
                tempSeasonList.add(new Season(aLanguage.getFile(),
                        tempSeasonNumber));

            }
        }

        return tempSeasonList;

    }
}
